
# -*- coding: utf-8 -*-


import unittest
import sys
import os
import time
import warnings

# 添加执行环境
file_exec_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
sys.path.insert(0, file_exec_path)
from framework_strategy.gopy.trader.engine import EmailEngine, MainEngine, EventEngine  # NOQA
from framework_strategy.gopy.base.api import API, Event  # NOQA
from framework_strategy.gopy.gateways.object import *  # NOQA
from framework_strategy.gopy.gateways.xt.v3.spot.xt_api import XTGateway  # NOQA
from framework_strategy.gopy.gateways.xt.v3.future.xt_future_api import XTFUTUREGateway  # NOQA
from framework_strategy.manager import *  # NOQA


def init_engine():
    event_engine = EventEngine()
    xt_gateway = XTGateway(event_engine, "BINANCE")
    event_engine.start()
    # 获取服务器时间同步获取
    api = API(event_engine)
    return event_engine, api


class FocusTest(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        warnings.simplefilter('ignore', ResourceWarning)

    @unittest.skip
    def test_server_init(self):

        event_engine = EventEngine()
        main_engine = MainEngine(event_engine)
        main_engine.add_gateway(XTGateway)
        main_engine.add_gateway(XTFUTUREGateway)

        server_time_event = ServerTimeData(_source="XT")
        api = main_engine.client

        nt = time.time()
        api.get_server_time(server_time_event)
        res = server_time_event.get_result(timeout=1)

        print("[*] res >>> ", res, time.time() - nt)
        time.sleep(5)
        main_engine.close()
        pass

    def test_manager_init(self):
        start()
        pass


if __name__ == "__main__":
    unittest.main()
    pass

